function flitered_data = FUN_plotDataDCTMinusFilter(fig,data, datam )
%FUN_plotDataDCTFilter Summary of this function goes here
%   Detailed explanation goes here

size = length(data);
sampletime = 0.01;                               %sample time that unit is second
t = 0:sampletime:(size-1) * sampletime;     %time point

figure(fig);clf();subplot(2,2,1);
plot(t,data,'k');
title('Time Domain Analysis');%axis([0 60 -200 200]);
xlabel('Time/s'); ylabel('Amplitude/Value')
title('Time domain orignal PPG data ');

samplefreq = 1/sampletime;                        %sample frequency that unit is Hz
f = (0:(size-1))/(size*2)*samplefreq;           %frequency point
dct_data=dct(data);
dct_data_abs=abs(dct_data);

figure(fig);subplot(2,2,3);
plot(f,dct_data_abs,'k');
title('Frequency Domain Analysis'); axis auto %axis([0 100 0 10^6]);
xlabel('Frequency/Hz'); ylabel('Amplitude/Value')
title('Frequency domain orignal PPG data ');

[dct_data_sort,index] = sort(dct_data_abs,'descend');
i = 1;
while norm(dct_data(index(1:i)))/norm(dct_data)<0.99
   i = i + 1;
end
Needed = i;
dct_data(index(Needed+1:end)) = 0;
dct_data(1:0.5*120) = 0;  %0.5Hz
flitered_data = idct(dct_data);

figure(fig);subplot(2,2,2);hold on;
plot(t,flitered_data,'b');
title('Time Domain Filtered Analysis');%axis([0 60 -200 200]);
xlabel('Time/s'); ylabel('Amplitude/Value')
% legend('Original',['Reconstructed, N = ' int2str(Needed)], ...
%        'Location','SouthEast')

figure(fig);subplot(2,2,4);
plot(f,abs(dct_data),'b');
title('Frequency Domain filtered Analysis');axis auto %axis([0 100 0 10^6]);
xlabel('Frequency/Hz'); ylabel('Amplitude/Value')
% legend('Original',['Reconstructed, N = ' int2str(Needed)], ...
%        'Location','SouthEast')
end



